import { http } from "@/utils/http";

// 分页响应接口
interface PageResponse<T> {
  total: number;
  list: T[];
}

// 通用响应接口
export interface ApiResponse<T = any> {
  code: number;
  data?: T;
  message: string;
}

// 投诉管理查询参数
export interface ComplaintManagementQueryDto {
  page?: number;
  limit?: number;
  cellId?: string;
  roomNumber?: string;
  complainant?: string;
  contactPhone?: string;
  status?: string;
  keyword?: string;
  tenantId?: number;
}

// 投诉管理基础数据
export interface ComplaintManagementBase {
  id?: number;
  cellId: string;
  roomNumber: string;
  complainant: string;
  complaintDate: string | Date;
  contactPhone: string;
  status: string;
  complaintContent: string;
  handler?: string;
  handlingTime?: string | Date;
  revisitPerson?: string;
  revisitTime?: string | Date;
  revisitContent?: string;
  revisitStatus?: string;
  processingResult?: string;
  attachmentUrl?: string;
}

// 投诉管理实体类
export interface ComplaintManagement extends ComplaintManagementBase {
  tenantId?: number;
  isDeleted?: number;
}

// 投诉管理列表展示对象
export interface ComplaintManagementListVo extends ComplaintManagementBase {
  cellName: string;
}

// 投诉管理更新DTO
export type UpdateComplaintManagementDto = ComplaintManagementBase & { tenantId?: number };

/** 获取投诉列表 */
export const getComplaintManagementList = (data?: ComplaintManagementQueryDto) => {
  return http.request<ApiResponse<PageResponse<ComplaintManagementListVo>>>('post', '/complaintManagement/list', { data });
};

/** 根据ID查询投诉详情 */
export const getComplaintManagementById = (id: number) => {
  return http.request<ApiResponse<ComplaintManagement>>('get', '/complaintManagement/find', { params: { id } });
};

/** 添加投诉记录 */
export const addComplaintManagement = (data?: UpdateComplaintManagementDto) => {
  return http.request<ApiResponse>('post', '/complaintManagement/add', { data });
};

/** 更新投诉记录 */
export const updateComplaintManagement = (data?: UpdateComplaintManagementDto) => {
  return http.request<ApiResponse>('put', '/complaintManagement/update', { data });
};

/** 删除投诉记录 */
export const deleteComplaintManagement = (id: number) => {
  return http.request<ApiResponse>('delete', '/complaintManagement/delete', { params: { id } });
};